<html>
<head><meta charset="utf-8"><title>safe target_feature functions for wasm · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html">safe target_feature functions for wasm</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="238667618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238667618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238667618">(May 13 2021 at 19:23)</a>:</h4>
<p>I've proposed <a href="https://github.com/rust-lang/rust/pull/84988">https://github.com/rust-lang/rust/pull/84988</a> for merge. It seems reasonable to me, given how WebAssembly works. Please take a look at it and see what you think.</p>



<a name="238667642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238667642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238667642">(May 13 2021 at 19:23)</a>:</h4>
<p>I nominated it for next week's meeting, but I'd love to handle it asynchronously.</p>



<a name="238675654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238675654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238675654">(May 13 2021 at 20:24)</a>:</h4>
<p>I think it's worth noting I recall some discussion (or maybe my own thinking) that ideally you'd also get these intrinsics for free as safe functions if we had some sort of "I'm only targeting platforms with X", roughly. I guess more portability lint desire :)</p>



<a name="238679585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238679585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238679585">(May 13 2021 at 20:54)</a>:</h4>
<p>IIRC that was the target_feature 1.1 RFC</p>



<a name="238679616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238679616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238679616">(May 13 2021 at 20:54)</a>:</h4>
<p><a href="https://github.com/rust-lang/rfcs/blob/master/text/2396-target-feature-1.1.md">https://github.com/rust-lang/rfcs/blob/master/text/2396-target-feature-1.1.md</a></p>



<a name="238679717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238679717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238679717">(May 13 2021 at 20:55)</a>:</h4>
<p>Yeah. This seems somewhat orthogonal, to me. I'd love to have both. :)</p>



<a name="238679796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238679796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238679796">(May 13 2021 at 20:55)</a>:</h4>
<p>For sure! I just wanted to note that the desire isn't unique to webassembly.</p>



<a name="238679930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238679930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238679930">(May 13 2021 at 20:56)</a>:</h4>
<p>Absolutely.</p>



<a name="238680016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238680016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238680016">(May 13 2021 at 20:57)</a>:</h4>
<p>I'd also love to have a compile-time-verifiable way to call functions with <code>target_feature</code> from safe code if I supply a static type-based proof that I've checked the CPU features, for instance.</p>



<a name="238680027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238680027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238680027">(May 13 2021 at 20:57)</a>:</h4>
<p>But that's a much more complicated proposition.</p>



<a name="238827748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238827748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238827748">(May 14 2021 at 20:49)</a>:</h4>
<p>That's pretty simple to put in a crate</p>



<a name="238857901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238857901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238857901">(May 15 2021 at 01:52)</a>:</h4>
<p>So apparently, to <span class="user-mention" data-user-id="132920">@gnzlbg</span>, the issue with <code>unsafe</code> on <code>target_feature</code> was not actually entirely on the processor being safe or not. It was also about the codegen backend and what sort of malevolent tricks it might pull:</p>
<p><a href="https://rust-lang.github.io/rfcs/2045-target-feature.html#make-target_feature-safe">https://rust-lang.github.io/rfcs/2045-target-feature.html#make-target_feature-safe</a><br>
<a href="https://github.com/rust-lang/rfcs/pull/2045#issuecomment-311325202">https://github.com/rust-lang/rfcs/pull/2045#issuecomment-311325202</a></p>



<a name="238858379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238858379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238858379">(May 15 2021 at 02:00)</a>:</h4>
<p>I don't think this necessarily means that this is invalid, but it does highlight that it's not entirely about the WebAssembly "decoder" but about the codegen backend, runtime, wasm's control flow integrity, AND its decode.</p>



<a name="238889690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/safe%20target_feature%20functions%20for%20wasm/near/238889690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/safe.20target_feature.20functions.20for.20wasm.html#238889690">(May 15 2021 at 11:11)</a>:</h4>
<p>At the very least we need to delve into the LLVM LangRef and find a guarantee that on a wasm target, calling a function with "bad" target_feature is <em>not</em> UB but a guaranteed trap on old interpreters.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>